package com.example.sqlitetest.Activity;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.sqlitetest.R;
import com.example.sqlitetest.db.MyDataBaseHelper;

import butterknife.ButterKnife;

public class InsertLiYanActivity extends AppCompatActivity {
    EditText name,liuyan;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_insertliuyan);
        ButterKnife.bind(this);
        Context context;


        //初始化数据库对象
        MyDataBaseHelper helper = new MyDataBaseHelper(this);//创建并初始化DBOpenHelper对
        final SQLiteDatabase db = helper.getWritableDatabase();//初始化SQLiteDatabase对象

        Button Btn  = findViewById(R.id.btn);

        name = findViewById(R.id.name);
        liuyan = findViewById(R.id.liuyan);




       /*按钮点击事件*/
        Btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final String username = name.getText().toString();
                final String liuyans  =  liuyan.getText().toString();

                ContentValues values = new ContentValues();
                values.put("username",username);
                values.put("liuyan",liuyans);

                db.insert("liuyan", null, values);
                values.clear();
                Toast.makeText(InsertLiYanActivity.this,"添加留言成功", Toast.LENGTH_SHORT).show();
                finish();
            }
        });
    }

}
